
#include <algorithm>
#include <cassert>

#include <sstream>
#include <boost/dynamic_bitset.hpp>

typedef long long           int64_t;
typedef unsigned long long  uint64_t;

int int_ln2 ( int64_t v )
{
    const unsigned int64_t b[] = {0x2ULL, 0xCULL, 
        0xF0ULL, 0xFF00ULL, 0xFFFF0000ULL, 0xFFFFFFFF00000000};
    const unsigned int S[] = {1, 2, 4, 8, 16, 32};

    unsigned int r = 0;
    for( int i=5; i >= 0; i-- )
    {
        if (v & b[i])
        {
            v >>= S[i];
            r |= S[i];
        } 
    }

    return r;
}


namespace graph
{
    namespace graph_sparse6_helper
    {
        const char fst_ch = 63;
        const char lst_ch = 126;
        const int ch_bit_width = 6;

        int64_t read_n ( istream& in_buf )
        {
            const int magic_len_list[] = { 1, 3, 6 };

            int magic_num_cntr = 0;
            char c = 0;

            do
            {
                in_buf.get(c);
                assert( c >= fst_ch && c <= lst_ch );
                magic_num_cntr++;
            }
            while ( lst_ch <= c );

            int64_t result = c - fst_ch;

            int chars = magic_len_list[magic_num_cntr];
            for ( int j=1; j<chars; j++ )
            {
                in_buf.get(c);
                assert( c >= fst_ch && c <= lst_ch );
                result|= (int64_t)(c - fst_ch) << ( j*ch_bit_width );
            }

            return result;
        }

        void read_edges( int64_t n, istream& in_buf )
        {
            int64_t k = int_ln2 ( ( n-1 ) << 1 ); 

            boost::dynamic_bitset<uint64_t> edge_bits;
            
            while( !in_buf.eof() )
            {
                char c;
                in_buf.get(c);
                assert( c >= fst_ch && c <= lst_ch );
                c -= fst_ch;
            
                for( int i=0; i<ch_bit_width; i++ )
                {
                    edge_bits.push_back(0x1 & (c >> i) );
                }
            }

            int m = edge_bits.size() / ( k + 1 );

            vector<bool> B( m );
            vector<int_64_t> x( m );

            for( int i=0; i<m; i++ )
            {
                B[i] = edge_bits[i * ( k + 1 )];
                x[i] = 0;

                for( int j=0; j<k; j++ )
                {
                    x[i] |= edgebits[i * ( k + 1 ) + 1 + j] << j;
                }
            }

            int64_t v = 0;
            for( int i=0; i<m; i++ )
            {
                if( B[i] )
                    v++;
                
                if( x[i] > v )
                    v = x[i];
                else
                    
            }
        }
    };

    class simple_graph
    {
        public:
            Graph()
            {}

            ~Graph()
            {}

            void readGraph6FromStream ( istream& in )
            {
                stringstream s;

                in.get( s );
                int64_t n = readN( s );

            } 
    };
};
